// const zlib=require('zlib');
//
// let str='{"5ba1f8c21d2d41310c84561a":{x:21.145621456,y:34.156468784521},"5ba1f8c21d2d41310c84561f":{x:21.145621456,y:34.156468784521}}';
// zlib.gzip(str,(err, zip)=>{
//    console.log(str.length,zip.toString('binary').length);
// });
// console.log('登陆',JSON.stringify({r:'login',_id:'5ba1f8c21d2d41310c84561a',token:'2ff42bba52053def87bbb114a448429b'}));
// console.log('加入排位',JSON.stringify({r:'matching'}))

//
// const Sprite=require('./model/Sprite');
//
// let a=new Sprite({properties:{x:1,y:2}});
// setTimeout(()=>{
//     a.x=3;
//     a.y=4;
//     console.log(a.getPropertiesChange());
// },1000);
// a.on('properties',function(value){
//     console.log(value);
// });

//
// let upDate=new Date('2018-11-14');
// let now=new Date(1542768101625);
// console.log(now.toLocaleString())
// console.log(upDate.getTime())
//
const mongoose = require('mongoose');
const fs = require('fs');
require('./db/mongodb').load();
//
// // require('./db/default/registerDefaultGameUser');
let run=async function(){
    console.log('获取机器人中。。。')
    let GameUserModel=mongoose.models['GameUser'];
    let users=await GameUserModel.find({lastLoginTick: {$gt: 1568337475000}}).skip(500).limit(100);//.sort({'social.love':-1});
    console.log('users.length =====', users.length);
    let data1 = '';
    let data2 = '';
    for(let i=0;i<users.length;i++){
        if(users[i].nickname.includes('测试用户'))continue;
        data1 += '|' + users[i].nickname;
        data2 += '|' + users[i].headImgUrl;
        // console.log('nickname ==', users[i].nickname, users[i].headImgUrl);
    //     // if(users[i].status===2){
    //     // users[i].ppt.role=users[i].sex==1?300:400;
    //     // //}
    //     // //
    //     users[i].ppt.level=0;
    //     // //users[i].mission.missions=[];
    //     // //users[i].ppt.skins=[];
    //     // // users[i].store.goldCoin=100;
    //     // // users[i].store.diamond=100;
    //     await users[i].save();
    }
    fs.writeFileSync("nickname.txt", data1);
    fs.writeFileSync("headimgurl.txt", data2);
};
//
setTimeout(()=>{
    // run();
}, 5000);

// let time=new Date(1546860966905);
// console.log(time.toLocaleString())

let changeCensusDate = async function () {
    const ChannelCensusModel = mongoose.models['ChannelCensus'];
    let data  = await ChannelCensusModel.find({});
    for(let item of data){
        let date = new Date(item.addDate);
        item.addDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate());
        await item.save();
    }
};

// changeCensusDate();

let fun = async function () {
    let nickname = '文人';
    let GameUserModel = mongoose.models['GameUser'];
    let gameUser = await GameUserModel.findOne({_id: '5d8356ea34959a34795e65cf'});
    if(gameUser){
        let res = await GameUserModel.remove({_id: '5d8356ea34959a34795e65cf'});
        console.error('文人用户删除成功', res);
    }
};
setTimeout(()=>{
    fun();
}, 5000)
